import 'package:inmotion_pro/service/realtime_data_server/vehicle_realtime_data/vehicle_statistics_once.dart';
import 'package:lx_widgets_library/http/base_data.dart';
import 'package:safemap/safemap.dart';

// 骑行记录响应数据模型
class RideRecordResponseModel extends BaseData {
  // 骑行记录
  List<VehicleStatisticsOnce> ridingRecords;

  // 总数量
  int totalCount;

  // 统计信息
  RideRecordStats rideRecordStats;

  RideRecordResponseModel({
    this.ridingRecords = const [],
    this.totalCount = 0,
    RideRecordStats? rideRecordStats,
  }) : rideRecordStats = rideRecordStats ?? RideRecordStats();

  factory RideRecordResponseModel.fromJson(Map<String, dynamic> json) {
    SafeMap safeMap = SafeMap(json);
    return RideRecordResponseModel(
      ridingRecords: (safeMap['records'].list ?? [])
          .map((item) => VehicleStatisticsOnce.fromMap(item))
          .toList(),
      totalCount: safeMap['total'].toInt ?? 0,
      rideRecordStats: safeMap['stats'].map != null
          ? RideRecordStats.fromJson(
              safeMap['stats'].map as Map<String, dynamic>)
          : RideRecordStats(),
    );
  }
}

// 骑行记录统计信息模型
class RideRecordStats {
  // 能耗
  int consumption;

  // 总时长
  int rideTime;

  // 总里程
  int mileage;

  RideRecordStats({
    this.consumption = 0,
    this.rideTime = 0,
    this.mileage = 0,
  });

  factory RideRecordStats.fromJson(Map<String, dynamic> json) {
    SafeMap safeMap = SafeMap(json);
    return RideRecordStats(
      consumption: safeMap['consumption'].toInt ?? 0,
      rideTime: safeMap['ride_time'].toInt ?? 0,
      mileage: safeMap['mileage'].toInt ?? 0,
    );
  }
}
